package com.learn.spring;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author zhongshitao
 * @date 2020/9/29 1:57 下午
 */
public class ToolProxy implements InvocationHandler {


    private Object obj;

    public ToolProxy(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        return method.invoke(obj,objects);
    }

    public <T> T getProxy() {
        return (T) Proxy.newProxyInstance(obj.getClass().getClassLoader(),obj.getClass().getInterfaces(),this);
    }
}
